<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:12
 */

namespace app\api\validate;

class CheckValidate extends \think\Validate
{

    const SCENE_SEND_MSG = 'send_msg'; //发送短信
    const SCENE_CHECK_CODE = 'check_code'; //校验验证码
    const SCENE_BIND_TEL = 'bind_tel'; //绑定手机号
    const SCENE_LOGIN_TEL = 'login_tel'; //手机验证码登陆
    const SCENE_FORGET = 'forgte'; //忘记密码
    const SCENE_EDIT_PWD = 'deit_pwd'; //修改密码



    protected $rule = [
        'mid' => 'require|number',
        'tel' => 'require|isTel',
        'type' => 'require|number|between:1,5',
        'code' => 'require',
        'pwd' => 'require|max:32',
        'pwd1' => 'require|max:32',
    ];


    protected $message  = [
        'mid.require' => '会员id缺失',
        'tel.require' => '手机号缺失',
        'mid.number' => '会员id必须为数字',
        'type.number' => '类型必须为数字',
        'type' => '类型必须在1-5之间',
        'code.require' => '验证码必须',
        'pwd.require' => '密码必须',
        'pwd.max' => '密码最长32',
        'pwd.require' => '密码必须',
        'pwd.max' => '密码最长32',
    ];

    protected $scene  = [
       self::SCENE_SEND_MSG => ['tel','type'],
       self::SCENE_CHECK_CODE => ['tel', 'code', 'type'],
       self::SCENE_BIND_TEL => ['tel', 'code'],
       self::SCENE_LOGIN_TEL => ['tel', 'pwd'],
       self::SCENE_FORGET => ['tel', 'code', 'pwd'],
       self::SCENE_EDIT_PWD => ['mid','tel', 'code', 'pwd', 'pwd1'],
    ];
    
    /**
    * 验证手机号
    */
    public function isTel($val){
        return preg_match("/^(13|14|15|16|17|18|19)[0-9]{9}$/", $val) ? true : '请输入合法的手机号';
    }

}